import { message } from 'antd';
import { TipsErrorModalNew } from '@/components/TipsErrorModalNew';
import { collectNeedPlanServices } from '../services/UpdateService';
import { getCompanyID, getInvoiceCode, getPosIDs, getUserDepID, getUserID } from '@/utils';

export const CollectModal = ({
  // resObj,
  requestUrl,
  onClose,
  reqBody = {},
  modalTip,
  reloadRequest,
  modalTitle = '提示',
  bodyWidth,
}: Record<string, any>) => {
  const handleRemoveCallback = (res) => {
    if (res?.msgFlag) {
      message?.success(res?.msg);
      reloadRequest();
    }
  };

  const { collectNeedPlanRun, collectNeedPlanLoading } = collectNeedPlanServices(handleRemoveCallback, requestUrl);

  return (
    <TipsErrorModalNew
      onClose={onClose}
      modalTitle={modalTitle}
      modalOnOK={() => {
        const reqParams: Record<string, any> = {
          ...reqBody,
          needCode: getInvoiceCode('XQ'),
          createrID: getUserID(),
          createPositionID: getPosIDs(),
          createDepartmentID: getUserDepID(),
          createCompanyID: getCompanyID(),
        };
        collectNeedPlanRun(reqParams);
      }}
      modalLoading={collectNeedPlanLoading}
      bodyWidth={bodyWidth}
      modalTip={modalTip}
    />
  );
};
